#include <bits/stdc++.h>
// 2025/02/23
// tag: 
// Author: Forever
using namespace std;

#pragma GCC optimize("Ofast")

using int64 = int64_t;

int n, m;
unordered_set<int> vis;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    int ans = INT_MAX, cnt = 0;
    queue<int> q;
    q.push(n);
    vis.insert(n);
    while (!q.empty()){
        int len = q.size();
        for (int i = 0; i < len; i++){
            int cur = q.front();
            q.pop();
            if (cur >= m){
                ans = min(ans, cnt + cur - m);
            }
            else{
                if (vis.find(cur - 1) == vis.end() && cur > 0){
                    q.push(cur - 1);
                    vis.insert(cur - 1);
                }
                if (vis.find(cur * 2) == vis.end()){
                    q.push(cur * 2);
                    vis.insert(cur * 2);
                }
            }
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}